<?php

require_once './application/controllers/ControllerBase.php';
require_once './application/core/Common/CommonCore.php';

///
/// Classe gerant les connections / deconnections des utilisateurs
///
class InterfaceController extends ControllerBase
{

    protected $_currentInterface;

    function indexAction()
    {
        $this->verifConnexion();
        $this->_redirector->gotoSimple('', '');
    }

    function ajoutertabAction()
    {
        $this->_currentInterface = new zend_session_namespace('interface', true);
        $this->noRender();
        $params = $this->_request->getParams();
        if (isset($params["url"]) && isset($params["label"]))
        {
            $this->_currentInterface->tabs[$params["url"]] = $params["label"];
            print_r($this->_currentInterface->tabs);
            echo 1;
        } else
        {
            echo 0;
        }
    }

    function retirertabAction()
    {
        $this->_currentInterface = new zend_session_namespace('interface', true);
        $this->noRender();
        $params = $this->_request->getParams();
        if (isset($params["url"]))
        {
            unset($this->_currentInterface->tabs[$params["url"]]);
            print_r($this->_currentInterface->tabs);
            echo 1;
        } else
        {
            echo 0;
        }
    }

    function affichertabAction()
    {
        $this->noRender();
        $this->_currentInterface = new zend_session_namespace('interface', true);
        $json = "";
        $indice = 0;
        $json .= "{'tab':[";
        if (isset($this->_currentInterface->tabs))
        {
            foreach ($this->_currentInterface->tabs as $key => $value)
            {
                if ($indice > 0)
                {
                    $json .= ",";
                }
                $json .= "{'item':{'url':'" . $key . "', 'label':'" . $value . "' }}";
                $indice++;
            }
        }
        $json .= "]}";
        echo $json;
    }

}
